package com.cqu.lpss.service.impl;

import com.cqu.lpss.mapper.ContestantsMapper;
import com.cqu.lpss.pojo.Contestants;
import com.cqu.lpss.pojo.PageBean;
import com.cqu.lpss.service.ContestantsInterface;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ContestantsImpl implements ContestantsInterface {
    @Autowired
    ContestantsMapper contestantsMapper;
    @Override
    public Contestants login(Contestants contestant) {
        Contestants ans = contestantsMapper.findByIdAndPassword(contestant.getConId(),contestant.getConPassword());
        return ans;
    }

    @Override
    public Contestants findById(String conId) {
        Contestants ans = contestantsMapper.findById(conId);
        return ans;
    }

    @Override
    public PageBean<Contestants> list(int currentPage, int pageSize,
                                      String conId, String conName,
                                      Integer conLowAge, Integer conHighAge,
                                      Integer conGender, String conEmail,
                                      String conPhone, Integer conClass) {
        PageHelper.startPage(currentPage,pageSize);
        List<Contestants> conlist= contestantsMapper.list(conId, conName, conLowAge, conHighAge, conGender, conEmail, conPhone, conClass);
        Page<Contestants> conpage = (Page<Contestants>) conlist;
        PageBean<Contestants> pageBean = new PageBean<>(conpage.getTotal(),conlist);
        return pageBean;
    }

    @Override
    public Contestants findByPhone(String phone) {
        Contestants contestants = contestantsMapper.findByPhone(phone);
        return contestants;
    }

    @Override
    public int insert(Contestants contestants) {
        int ans = contestantsMapper.insert(contestants.getConId(),contestants.getConName(),contestants.getConAge()
        ,contestants.getConGender()
        ,contestants.getConEmail()
        ,contestants.getConPassword()
        ,contestants.getConPhone()
        ,contestants.getConClass()
        ,contestants.getConBirth()
        ,contestants.getConCreatetime()
        ,contestants.getConUpdatetime());
        return ans;
    }

    @Override
    public int PersonCenter_upload(String newpassword,String phone,String email, String Id) {
        int ans = contestantsMapper.PersonCenter_upload(newpassword, phone, email, Id);
        return ans;

    }

    @Override
    public List<Map<Integer, Long>> passfirstPrj_groupByClass() {
        List<Map<Integer, Long>> passfirstPrjGroupByClass = contestantsMapper.passfirstPrj_groupByClass();
        return passfirstPrjGroupByClass;
    }

    @Override
    public List<Map<Integer, Long> > UploadCon_GroupByClass() {
        List<Map<Integer, Long> > uploadedCon_groupByClass = contestantsMapper.UploadedCon_groupByClass();
        return uploadedCon_groupByClass;
    }

    @Override
    public int totalnum() {
        int totalnum = contestantsMapper.totalnum();
        return totalnum;
    }
}
